package com.cleaningcloud.cld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.cleaningcloud.cld.domain.CldNoticeConfirm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldNotice;
import com.cleaningcloud.cld.service.ICldNoticeService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 通知公告Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-27
 */
@RestController
@RequestMapping("/notice")
public class CldNoticeController extends BaseController
{
    @Autowired
    private ICldNoticeService cldNoticeService;

    /**
     * 查询通知公告列表
     */
    @RequiresPermissions("cld:notice:list")
    @GetMapping("/list")
    public TableDataInfo list(CldNotice cldNotice)
    {
        startPage();
        List<CldNotice> list = cldNoticeService.selectCldNoticeList(cldNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @RequiresPermissions("cld:notice:export")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldNotice cldNotice)
    {
        List<CldNotice> list = cldNoticeService.selectCldNoticeList(cldNotice);
        ExcelUtil<CldNotice> util = new ExcelUtil<CldNotice>(CldNotice.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @RequiresPermissions("cld:notice:query")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Long noticeId)
    {
        return success(cldNoticeService.selectCldNoticeByNoticeId(noticeId));
    }

    /**
     * 新增通知公告
     */
    @RequiresPermissions("cld:notice:add")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldNotice cldNotice)
    {
        return toAjax(cldNoticeService.insertCldNotice(cldNotice));
    }

    /**
     * 修改通知公告
     */
    @RequiresPermissions("cld:notice:edit")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldNotice cldNotice)
    {
        return toAjax(cldNoticeService.updateCldNotice(cldNotice));
    }

    /**
     * 删除通知公告
     */
    @RequiresPermissions("cld:notice:remove")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Long[] noticeIds)
    {
        return toAjax(cldNoticeService.deleteCldNoticeByNoticeIds(noticeIds));
    }

    /**
     * @Author Shaw
     * @Description 根据通知公告ID获取确认明细列表
     * @date: 2025-03-19 10:24
     * @param: //TODO
     */
    @RequiresPermissions("cld:notice:query")
    @GetMapping("/getNoticeConfirmList")
    public TableDataInfo getNoticeConfirmList(CldNoticeConfirm cldNoticeConfirm) {
        startPage();
        List<CldNoticeConfirm> list = cldNoticeService.getNoticeConfirmList(cldNoticeConfirm);
        return getDataTable(list);
    }
}
